/**
 * Class is the base class used to build a complete
 * and organized object-oriented model in JavaScript.
 *
 * It provides very basic and standard tools for debugging
 * purposes and also defines standard variables.
 *
 * @param name	(optional) the IObject's instance name
 */
function	Class(name)
{
	this._id			= IObject.ID++;	// unique ID
	this._name			= name;			// (non-unique) name
	this._type			= 'IObject';	// type;
	this._className		= 'IObject';	// type;
	this._version		= 'x.xx.xx';	// development version number
	this._events		= new Object();	// events collection


//	alert('>>' + /(\w+)\(/.exec(this.constructor.toString())[1]);

	this.destroy		= function()
	{
		return (IObject.destroy(this));
	}

	this.getId			= function()
	{
		return (this._id);
	}

	this.getName		= function()
	{
		return (this._name);
	}

	this.getType		= function()
	{
		return (this._type);
	}

	this.getClassName	= function()
	{
		return (this._className);
	}

	this.getVersion		= function()
	{
		return (this._version);
	}

	this.toString		= function()
	{
		var	str		= new String();

		for (element in this)
		{
			if (typeof(this[element]) != 'function')
			{
				str += element + ':\t[' + this[element] + ']\n';
			}
		}
		return (str);
	}

	this.toHTML			= function()
	{
		var	html	= new String();

		html += '<DIV id="' + this.getId() + '" name="' + this.getName() + '">\n';
		html += ' <TABLE>\n';
		for (element in this)
		{
			if (typeof(this[element]) != 'function')
			{
				html += '  <TR id="' + this.getId() + '__' + element + '">\n';
				html += '   <TD name="key">\n';
				html += '    ' + element + '\n';
				html += '   </TD>\n';
				html += '   <TD name="value">\n';
				html += '    ' + this[element] + '\n';
				html += '   </TD>\n';
				html += '  </TR>\n';
			}
		}
		html += ' </TABLE>\n';
		html += '</DIV>\n';
		return (html);
	}

	Class.instances[this.getId()] = this;
} // !IObject
Class.ID			= 0;			//	Static ID counter
Class.instances	= new Object();	//

Class.clear	= function()
{
	if (IObject.instances)
	{
		for (i in IObject.instances)
		{
			var	instance	= IObject.getInstance(i);

			if (instance != null)
			{
				instance.destroy();
			}
			else
			{
				delete IObject.instances[i];
			}
		}
	}
}
Class.destroy	= function(iobject)
{
	if (iobject)
	{
		if (iobject.getId &&
			IObject.instances && IObject.instances[iobject.getId()])
		{
			delete IObject.instances[iobject.getId()];
		}
		delete iobject;
		return (true);
	}
	return (false);
}
Class.getInstance	= function(id)
{
	if (id && IObject.instances && IObject.instances[id])
	{
		return (IObject.instances[id]);
	}
	return (null);
}


if ((typeof(jssl) != 'undefined') && jssl && (jssl != null))
{
	if ((typeof(jssl) != 'undefined') && jssl.lang)
	{
		jssl.lang.Class = Class;
	}
	else
	{
		jssl.lang	=
		{
			Class	: Class
		};
	}
}
else
{
	jssl	=
	{
		lang	:
		{
			Class	: Class
		}
	};
}
